package com.loto.insurance.mis.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.loto.insurance.mis.web.authority.INSAuthority;
import com.loto.insurance.mis.web.entity.UserInfo;
import com.loto.insurance.mis.web.enumeration.IsActiveEnum;
import com.loto.insurance.mis.web.enumeration.MenuEnum;
import com.loto.insurance.mis.web.service.UserInfoService;
import com.loto.insurance.mis.web.utils.Config;

@Controller
public class UserController {
  @Autowired
  UserInfoService userInfoService;

  @INSAuthority(authorityMenu = MenuEnum.USER_LIST)
  @RequestMapping(value = "/user/list", method = RequestMethod.GET)
  public String userlist(Model model) {
	model.addAttribute("subId", MenuEnum.USER_LIST.getIndex());
	return "user/user_list";
  }

  @INSAuthority(authorityMenu = MenuEnum.USER_LIST)
  @RequestMapping(value = "/user/detail", method = RequestMethod.GET)
  public String userdetail(
	  @RequestParam(value = "id", required = false, defaultValue = "-1") long userId,
	  Model model) {
	model.addAttribute("statusList", IsActiveEnum.values());
	Config c = new Config();

	if (userId > 0) {
	  UserInfo userInfo = userInfoService.findUserById(userId);
	  model.addAttribute("user", userInfo);
	  model.addAttribute("config",
		  c.getCheckedBaseMenuConfigFile(userInfo.getUserName()));
	} else
	  model.addAttribute("config", c.getBaseMenuConfigFile());

	return "user/user_detail";
  }
}
